
import os
import sys
import warnings
import subprocess
from colorama import Fore
from concurrent.futures import ThreadPoolExecutor
# 获取当前脚本的完整路径
script_path = os.path.abspath(sys.argv[0])
# 从完整路径中获取目录
script_dir = os.path.dirname(script_path)
# 从完整路径中分离出文件名
script_name = os.path.basename(script_path)
# 使用 splitext() 函数分离文件名和扩展名
script_name_without_extension, _ = os.path.splitext(script_name)

print(Fore.YELLOW+f"python script name:", sys.argv[0])
if len(sys.argv)!=2:
    print(Fore.RED+f"you need python params!")
    sys.exit()

current_path=script_dir+"/"+sys.argv[1]+"/"
print(Fore.WHITE+f"current path:", current_path)


# 定义用于执行脚本的函数
def run_script(script_path):
    subprocess.run(["python3", script_path])
    print(Fore.GREEN+f"python3 ", script_path)

# 定义存放脚本的路径
scripts_dir = current_path  # 请替换为实际的路径

# 获取路径下的所有.py文件
# scripts = [os.path.join(scripts_dir, f) for f in os.listdir(scripts_dir) if f.endswith(".py")]

# 使用 os.walk 来递归获取所有 .py 文件
scripts = [os.path.join(root, f) 
           for root, dirs, files in os.walk(current_path) 
           for f in files if f.endswith(".py")]

# 使用线程池来并行运行脚本
with ThreadPoolExecutor() as executor:
    executor.map(run_script, scripts)